﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BusinessObject;
using YamahaTuanTruc.StatisticService;
namespace YamahaTuanTruc
{
    public partial class FrmBussinessStatisticbyQuarter : Form
    {
        public FrmBussinessStatisticbyQuarter()
        {
            InitializeComponent();
        }

        private void FrmBussinessStatisticbyQuarter_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 4; i++)
            {
                qcibQuarter.InputBox.Items.Add("Quý " + (i + 1));
            }

            for (int i = 2005; i <= DateTime.UtcNow.Year; i++)
            {
                this.qcibYear.InputBox.Items.Add(i);
            }
        }

        private void qcibQuarter_InputBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (qcibYear.InputBox.SelectedIndex != -1)
            {
                int quarter = qcibQuarter.InputBox.SelectedIndex;
                string year = qcibYear.InputBox.SelectedText.ToString();
                using (var service = new StatisticServiceClient())
                {
                    SuaChua[] lst = null;
                    try
                    {
                        lst = service.GetListBusByQuarter(quarter, year);
                        if (lst != null && lst.Length > 0)
                        {
                            for (int i = 0; i < lst.Length; i++)
                            {
                                dgvBussiness.Rows.Add();
                                string thanhtien = (lst[i].DonGia * lst[i].SoLuong + lst[i].ChiPhiPhatSinh + lst[i].TienBaoDuong).ToString();
                                dgvBussiness.Rows[i].Cells[0].Value = lst[i].Xe.NgayNhanXe.ToString();
                                dgvBussiness.Rows[i].Cells[1].Value = lst[i].Xe.Ten.ToString();
                                dgvBussiness.Rows[i].Cells[2].Value = lst[i].ChiTietCongViec.ToString();
                                dgvBussiness.Rows[i].Cells[3].Value = lst[i].DonGia.ToString();
                                dgvBussiness.Rows[i].Cells[4].Value = lst[i].SoLuong.ToString();
                                dgvBussiness.Rows[i].Cells[5].Value = lst[i].ChiPhiPhatSinh.ToString();
                                dgvBussiness.Rows[i].Cells[6].Value = lst[i].TienBaoDuong.ToString();
                                dgvBussiness.Rows[i].Cells[7].Value = thanhtien;
                                dgvBussiness.Rows[i].Cells[8].Value = lst[i].GhiChu;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Không có dữ liệu cho quý này.");
                        }
                    }
                    catch(Exception exception)
                    {
                        MessageBox.Show(exception.ToString());
                    }
                   
                }
            }
            else
            {
                
            }
        }

        private void qcibYear_InputBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            qcibQuarter_InputBox_SelectedIndexChanged(sender, e);
        }
    }
}
